package com.qqtech.qquan.push.helper;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.qqtech.core.common.constant.CoreConst;

public class PushCfg {
	public static final Logger logger = LoggerFactory.getLogger(PushCfg.class);
	private Properties props = null;
	private static PushCfg instance = new PushCfg();
	private final String prefix = "push.jg.";

	public static PushCfg getInstance() {
		return instance;
	}

	/**
	 * 单例
	 */
	private static class Singleton {
		private static final PushCfg instance = new PushCfg();
	}

	private PushCfg() {
		try {
			props = new Properties();
			InputStream reader = getClass().getClassLoader().getResourceAsStream("push.properties");
			InputStreamReader in = new InputStreamReader(reader, CoreConst.DEFAULT_CODETYPE);
			props.load(in);
		} catch (Exception e) {
			logger.error("加载推送配置文件失败", e);
		}
	}

	/**
	 * 获取实例
	 * 
	 * @return
	 */
	public static PushCfg getConfigHelper() {
		return Singleton.instance;
	}

	/**
	 * 获取值
	 * 
	 * @param key
	 * @return
	 */
	public String getValue(String key) {
		return props.getProperty(prefix + key).trim();
	}

	/**
	 * 根据key获取值
	 * 
	 * @param key
	 * @param defaultVal
	 * @return
	 */
	public String getValue(String key, String defaultVal) {
		String val = props.getProperty(prefix + key);
		if (null == val)
			return defaultVal;
		return val;
	}
}
